<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xwk="http://http://code.google.com/p/xworks"
	xmlns:inc="http://code.google.com/p/xworks..includes" exclude-result-prefixes="xwk inc">

	<xsl:template match="root" mode="inc:snippets">
		<ul class="xwk_menus_wrapper">
			<xsl:apply-templates select="menus" mode="identity_copy_menus"/>
		</ul>
	</xsl:template>

	<xsl:template match="root" mode="inc:menus">
		<ul class="xwk_menus_wrapper">
			<xsl:if test="@id">
				<xsl:attribute name="id">
					<xsl:value-of select="@id"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:apply-templates select="menus" mode="identity_copy_menus"/>
		</ul>
	</xsl:template>

	<xsl:template match="menus" mode="identity_copy_menus">
		<ul class="xwk_menus">
			<!--			<xsl:if test="(parent::menus) and not(preceding-sibling::menu_item)">
				<xsl:attribute name="style">display:block</xsl:attribute>
			</xsl:if>
			-->
			<xsl:if test="menu_item | menus">
				<xsl:attribute name="onmouseout">
					<xsl:text>Element.hide('ul_</xsl:text>
					<xsl:value-of select="generate-id(current())"/>
					<xsl:text>');</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="onmouseover">
					<xsl:text>Element.show('ul_</xsl:text>
					<xsl:value-of select="generate-id(current())"/>
					<xsl:text>');</xsl:text>
				</xsl:attribute>
			</xsl:if>
			<xsl:value-of select="@title"/>
			<xsl:if test="menu_item | menus">
				<ul>
					<xsl:if test="(parent::menus | parent::root)">
						<xsl:attribute name="style">display:none</xsl:attribute>
						<xsl:attribute name="class">submenus</xsl:attribute>
					</xsl:if>
					<xsl:attribute name="id">
						<xsl:value-of select="concat('ul_',generate-id(current()))"/>
					</xsl:attribute>
					<xsl:apply-templates select="menus | menu_item" mode="identity_copy_menus">
						<xsl:with-param name="parent_id"
							select="concat('ul_',generate-id(current()))"/>
					</xsl:apply-templates>
				</ul>
			</xsl:if>
		</ul>
	</xsl:template>

	<xsl:template match="menu_item" mode="identity_copy_menus">
		<xsl:param name="parent_id"/>
		<li>
			<a href="{@url}">
				<xsl:value-of select="."/>
			</a>
		</li>
	</xsl:template>

</xsl:stylesheet>
